home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
7_10.lha
/
7_10
/
p_restore.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-08
|
2KB
|
52 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
include <process.h>
include <debug.h> /* DELETE */
include <stackdir.h>
/ Restore a process to be the current process.
/ It doesn't return but instead comes back
/ through contextswitch(). It works by memcpy()'ing the
/ process' copy of the stack into the real stack.
/ First adjust the stack to make certain that
/ we are above that which needs to be restored.
/ This is done by recursively invoking restore().
tatic void restorestack(char *lowerbound, char *from,
unsigned size, jmp_buf jb)
memcpy(lowerbound, from, size);
longjmp(jb, 1);
/* NOTREACHED */
oid process::restore()
char x;
char *px = &x;
if (debug) /*DELETE*/ cerr << "process" << this << "::restore()\n";
if (debug) /*DELETE*/ cerr << "\tgrows_up == " << Stackdir.grows_up() << "\n";
if (debug) /*DELETE*/ cerr << "\t&x = ";
if (debug>1)/*DELETE*/ cerr << form("%#x", px);
if (debug) /*DELETE*/ cerr << "\n";
if (debug) /*DELETE*/ cerr << "\tt_stackbase = ";
if (debug>1)/*DELETE*/ cerr << form("%#x", t_stackbase);
if (debug) /*DELETE*/ cerr << "\n";
if (debug) /*DELETE*/ cerr << "\tt_stacksize = " << t_stacksize << "\n";
// if necessary, bump up the stack size
int diff = Stackdir.diff(px, t_stackbase);
if (debug) /*DELETE*/ cerr << "\tpx - t_stackbase = " << diff << "\n";
if (diff < t_stacksize)
restore();
// restore the stack
char *lowerbound = Stackdir.grows_up() ?
t_stackbase :
t_stackbase - t_stacksize;
t_thisprocess = this;
if (debug) /*DELETE*/ cerr << "<<<< process" << this << "::restore()\n";
restorestack(lowerbound, t_stack, t_stacksize, t_jb);
/* NOTREACHED */